package view.rules;

import javax.swing.*;

import net.miginfocom.swing.MigLayout;

public class InputSuffixPanel extends JPanel{
	
	private JLabel endStemLabel;
	private JTextField endStemTextField;
	private JLabel suffixLabel;
	private JTextField suffixTextField;
	private JLabel newSuffixLabel;
	private JTextField newSuffixTextField;
	private JPanel suffixPanel;
	
	private JLabel prefixLabel;
	private JTextField prefixTextField;
	private JPanel prefixPanel;
	private JLabel begStemLabel;
	private JTextField begStemTextField;
	private JLabel newPrefixLabel;
	private JTextField newPrefixTextField;
	
	private JPanel inPrefixPanel;
	private JLabel inPrefixLabel;
	private JTextField inPrefixTextField;
	private JLabel newInfixLabel;
	private JTextField newInfixTextField;
	
	private JPanel inSuffixPanel;
	
	private JLabel dummyLabel;
	private JLabel tempLabel;
	
	private JPanel panel;
	boolean prefix;
	boolean suffix;
	boolean inPrefix;
	boolean inSuffix;
	
	public InputSuffixPanel(){
		
		this.setLayout(new MigLayout());
		
		initComponent();
		addComponent();
	}

	private void initComponent() {
		
		panel = new JPanel();
		panel.setLayout(new MigLayout());
		
		suffixPanel = new JPanel();
		suffixPanel.setLayout(new MigLayout());
		
		endStemLabel = new JLabel("End of Stem");
		endStemTextField = new JTextField(30);
		suffixLabel = new JLabel("Suffix");
		suffixTextField = new JTextField(30);
		newSuffixLabel = new JLabel("New Suffix");
		newSuffixTextField = new JTextField(30);
		
		prefixPanel = new JPanel();
		prefixPanel.setLayout(new MigLayout());
		prefixLabel = new JLabel("Prefix");
		prefixTextField = new JTextField(30);
		begStemLabel = new JLabel("Beginning of Stem");
		begStemTextField = new JTextField(30);
		newPrefixLabel = new JLabel("New Prefix");
		newPrefixTextField = new JTextField(30);
		
		inPrefixPanel = new JPanel();
		inPrefixPanel.setLayout(new MigLayout());
		inPrefixLabel = new JLabel("Infix");
		inPrefixTextField = new JTextField(30);
		newInfixLabel = new JLabel("New Infix");
		newInfixTextField = new JTextField(30);
		
		inSuffixPanel = new JPanel();
		inSuffixPanel.setLayout(new MigLayout());
		
		dummyLabel = new JLabel("");
		tempLabel = new JLabel("");
		prefix = true;
		suffix = false;
		inPrefix = false;
		inSuffix = false;
		
	}

	private void addComponent() {
		
		addToPrefixPanel();
		panel.add(prefixPanel);
		add(panel);
	}
	

	
	private void addToPrefixPanel(){
		prefixPanel.add(prefixLabel);
		prefixPanel.add(prefixTextField);
		prefixPanel.add(begStemTextField);
		prefixPanel.add(begStemLabel, "wrap");
		prefixPanel.add(newPrefixLabel);
		prefixPanel.add(newPrefixTextField);
	}
	
	private void addToSuffixPanel(){
		suffixPanel.add(endStemLabel);
		suffixPanel.add(endStemTextField);
		suffixPanel.add(suffixTextField);
		suffixPanel.add(suffixLabel, "wrap");
		suffixPanel.add(dummyLabel);
		suffixPanel.add(tempLabel);
		suffixPanel.add(newSuffixTextField);
		suffixPanel.add(newSuffixLabel);
	}
	
	private void addToInPrefix(){
		inPrefixPanel.add(inPrefixLabel);
		inPrefixPanel.add(inPrefixTextField);
		inPrefixPanel.add(begStemTextField);
		inPrefixPanel.add(begStemLabel, "wrap");
		inPrefixPanel.add(newInfixLabel);
		inPrefixPanel.add(newInfixTextField);
	}
	
	private void addToInSuffix(){
		inSuffixPanel.add(endStemLabel);
		inSuffixPanel.add(endStemTextField);
		inSuffixPanel.add(inPrefixTextField);
		inSuffixPanel.add(inPrefixLabel, "wrap");
		inSuffixPanel.add(dummyLabel);
		inSuffixPanel.add(tempLabel);
		inSuffixPanel.add(newInfixTextField);	
		inSuffixPanel.add(newInfixLabel);	
	}
	
	public void setPanel(String affix){
		
		if (affix == "prefix" && prefix == false){
			

			if (suffix == true)
				panel.remove(suffixPanel);
			else if (inPrefix == true)
				panel.remove(inPrefixPanel);
			else if (inSuffix == true)
				panel.remove(inSuffixPanel);
			
			addToPrefixPanel();
			panel.add(prefixPanel, "wrap");
			panel.revalidate();
            panel.repaint();
            prefix = true;
            suffix = false;
            inPrefix = false;
            inSuffix = false;

		}
		
		if (affix == "suffix" && suffix == false){
			
			if (prefix == true)
				panel.remove(prefixPanel);
			else if (inPrefix == true)
				panel.remove(inPrefixPanel);
			else if (inSuffix == true)
				panel.remove(inSuffixPanel);

			addToSuffixPanel();
			panel.add(suffixPanel, "wrap");
			panel.revalidate();
            panel.repaint();
            suffix = true;
            prefix = false;
            inPrefix = false;
            inSuffix = false;

		}
		
		if (affix == "infixPrefix" && inPrefix == false){
			
			if (suffix == true)
				panel.remove(suffixPanel);
			else if (prefix == true)
				panel.remove(prefixPanel);
			else if (inSuffix == true)
				panel.remove(inSuffixPanel);

			addToInPrefix();
			panel.add(inPrefixPanel, "wrap");
			panel.revalidate();
            panel.repaint();
            suffix = false;
            prefix = false;
            inPrefix = true;
            inSuffix = false;

		}
		
		if (affix == "infixSuffix" && inSuffix == false){
			
			if (suffix == true)
				panel.remove(suffixPanel);
			else if (inPrefix == true)
				panel.remove(inPrefixPanel);
			else if (prefix == true)
				panel.remove(prefixPanel);
			
			addToInSuffix();
			panel.add(inSuffixPanel, "wrap");
			panel.revalidate();
            panel.repaint();
            suffix = false;
            prefix = false;
            inPrefix = false;
            inSuffix = true;

		}
		
	}

}
